#include <cstring>
#include <iostream>
using namespace std;
#include "string.h"

int String::num_strings = 0;

int String::HowMany() { return num_strings; }

//构造函数
String::String(const char *s) {
  len = std::strlen(s);
  str = new char[len + 1];
  strcpy(str, s);
  num_strings++;
}
String::String() {
  len = 4;
  str = new char[1];
  str[0] = '\0';
  num_strings++;
}

//拷贝构造
String::String(const String &st) {
  num_strings++;
  len = st.len;
  str = new char[len + 1];
  strcpy(str, st.str);
}

//析构函数
String::~String() {
  --num_strings;
  delete[] str;
}

String &String::operator=(const String &st) {
  if (this == &st) {
    return *this;
  }
  delete[] str;
  len = st.len;
  str = new char[len + 1];
  strcpy(str, st.str);
  return *this;
}
String &String::operator=(const char *s) {
  delete[] str;
  len = strlen(s);
  str = new char[len + 1];
  strcpy(str, s);
  return *this;
}

char &String::operator[](int i) { return str[i]; }
const char &String::operator[](int i) const { return str[i]; }

bool operator<(const String &st, const String &st2) {
  return (strcmp(st.str, st2.str) < 0);
}
bool operator>(const String &s1, const String &s2) { return s2.str < s1.str; }
bool operator==(const String &s1, const String &s2) {
  return (strcmp(s1.str, s2.str) == 0);
}
ostream &operator<<(ostream &os, const String &st) {
  os << st.str;
  return os;
}
istream& operator>>(istream &is,  String &st) {
  char tmp[String::CINLIN];
  is.get(tmp,String::CINLIN);
  if (is) {
    st = tmp;
  }
  while (is && is.get() != '\n') {
    continue;
  }
  return is;
}
